home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / matrx042.zip / MATADD.C < prev    next >
C/C++ Source or Header  |  1992-05-22  |  1KB  |  44 lines

  1. /*
  2. *-----------------------------------------------------------------------------
  3. *    file:    matadd.c
  4. *    desc:    matrix addition
  5. *    by:    ko shu pui, patrick
  6. *    date:    24 nov 91    v0.1
  7. *    revi:
  8. *    ref:
  9. *       [1] Mary L.Boas, "Mathematical Methods in the Physical Sciene,"
  10. *    John Wiley & Sons, 2nd Ed., 1983. Chap 3.
  11. *
  12. *-----------------------------------------------------------------------------
  13. */
  14. #include <stdio.h>
  15. #include "matrix.h"
  16.  
  17. /*
  18. *-----------------------------------------------------------------------------
  19. *    funct:    mat_add
  20. *    desct:    addition of two matrice
  21. *    given:    A, B = Compatible matrice to be added
  22. *    retrn:    NULL if malloc() fails
  23. *        else allocated matrix of A + B
  24. *    comen:
  25. *-----------------------------------------------------------------------------
  26. */
  27. MATRIX mat_add( A, B )
  28. MATRIX A, B;
  29. {
  30.     int    i, j;
  31.     MATRIX    C;
  32.  
  33.     if ((C = mat_creat( MatRow(A), MatCol(A), UNDEFINED )) == NULL)
  34.         return (NULL);
  35.  
  36.     for (i=0; i<MatRow(A); i++)
  37.     for (j=0; j<MatCol(A); j++)
  38.         {
  39.         C[i][j] = A[i][j] + B[i][j];
  40.         }
  41.     return (C);
  42. }
  43.  
  44.